<template>
     <div>
    <basic-container>
        <div style="width:400px;padding:40px 0" v-loading="isLoading">
 <avue-form  ref="form1" :disabled="isSubmiting" v-model="currentRow" :option="userWithdrawTableOption2"></avue-form>
          <div class="dialog-btns">
             <el-button
              type="primary"
              v-perm="'/admin/system_param/modify'"
              @click="handleSubmit"
              :loading="isSubmiting"
            >保存修改</el-button>
          </div>    
        </div>
          </basic-container>
    </div>    
</template>
<script>


export const userWithdrawTableOption2 = {
    border: false,
    index: false,
    selection: false,
    calcHeight: 350,
    emptyBtn: false,
    submitBtn:false,
    submitText: '确认打款',
    columnBtn: false,
    searchClearable: false,
    selectClearBtn: false,
    searchResetBtn: false,
    height: "auto",
    menu: true,
    menuAlign: "center",
    searchBtn: true,
    labelWidth: 160,
    refreshBtn: true,
    tip: false,
    addBtn: false,
    dialogWidth: '800px',
    dialogHeight: 'auto',
    menuWidth: 180,
    editBtn: false,
    viewBtn: false,
    delBtn: false,
    column: [
        {
            "label": "商户入驻保证金金额",
            "prop": "userMerchantCertAmount",
            "search": false,
            "type": "number",
            "fixed": false,
            precision:2,
            "width": "auto",
            "row": true,
            "minWidth": "120",
            "readonly": false,
            "span": 24,
            "display": true,
            "hide": false,
             "rules": [{
                "required": true,
                "message": "请输入商户入驻保证金金额",
                "trigger": "blur"
            }]
        },
        {
            "label": "商品平台佣金比例(%)",
            "prop": "goodsPlatformCommissionRate",
            "search": false,
            "type": "number",
            "fixed": false,
            "width": "auto",
            "row": true,
            "minWidth": "120",
            precision:2,
            "readonly": false,
            "span": 24,
            "display": true,
            "hide": false,
             "rules": [{
                "required": true,
                "message": "请输入商品平台佣金比例",
                "trigger": "blur"
            }]
        },
        {
            "label": "推广佣金比例上限(%)",
            "prop": "shareAwardPercent",
            "search": false,
            "type": "number",
            "fixed": false,
            "width": "auto",
            "row": true,
            "minWidth": "120",
            precision:2,
            "readonly": false,
            "span": 24,
            "display": true,
            "hide": false,
             "rules": [{
                "required": true,
                "message": "请输入推广佣金比例上限%",
                "trigger": "blur"
            }]
        }
    ]
};
import * as apiObj from "../../api/sysParam";
// 商品平台佣金比例
const goodsPlatformCommissionRate = 'goodsPlatformCommissionRate';
// 商户入驻保证金金额
const userMerchantCertAmount = 'userMerchantCertAmount';
// 分销比例
const shareAwardPercent = 'shareAwardPercent';
export default {
    data(){
        return {
            userWithdrawTableOption2,
            isSubmiting:false,
            isLoading:false,
            currentRow:{
                userMerchantCertAmount:'',
                goodsPlatformCommissionRate:'',
                shareAwardPercent:''
            }
        }
    },
    created(){
        this.loadData();
    },
    methods:{
        handleSubmit(){
            this.$refs.form1.validate(v=>{
                if(!v){
                    return;
                }
                this.isSubmiting = true;
                Promise.all([
                    apiObj.modify(goodsPlatformCommissionRate,this.currentRow.goodsPlatformCommissionRate),
                    apiObj.modify(userMerchantCertAmount,this.currentRow.userMerchantCertAmount),
                    apiObj.modify(shareAwardPercent,this.currentRow.shareAwardPercent)
                ])
                .then(() => {
                    this.success();
                }).finally(()=>{
                    this.isSubmiting = false;
                });
            });
        },
        loadParamValue(key){
            return apiObj.show(key);
        },
        loadData(){
            this.isLoading = true;
            Promise.all([
                this.loadParamValue(goodsPlatformCommissionRate).then(data=>{
                    this.currentRow.goodsPlatformCommissionRate = data.paramValue;
                }),
                this.loadParamValue(userMerchantCertAmount).then(data=>{
                    this.currentRow.userMerchantCertAmount = data.paramValue;
                }),
                this.loadParamValue(shareAwardPercent).then(data=>{
                    this.currentRow.shareAwardPercent = data.paramValue;
                })
            ]).finally(()=>{
                this.isLoading = false;
            });
        }
    }
}
</script>
<style lang="scss">
.dialog-btns{
    padding-left: 190px;
}
</style>
